<template>
  <div class="StatisticsList">
    <el-main class="StatisticsList">
      <div>
        <el-form ref="form" :model="form">
          <el-form-item>
            <el-row>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <el-input
                    placeholder="请输入关键字进行搜索"
                    v-model="keywords"
                    class="input-with-select"
                    style="width:270px;"
                  >
                    <el-button slot="append" icon="el-icon-search" @click="search"></el-button>
                  </el-input>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple-light">
                  <el-button type="primary" icon="el-icon-document" @click="ExportAssetInfo">导出</el-button>
                </div>
              </el-col>
            </el-row>
          </el-form-item>
        </el-form>
      </div>
      <el-table
        ref="multipleTable"
        :data="tableData3"
        border
        stripe
        height="355"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="State" label="状态" width="150" :formatter="formatState"></el-table-column>
        <el-table-column prop="pictureUrl" label="照片" width="120">
          <!-- 图片的显示 -->
          <template slot-scope="scope">
            <img v-if="scope.row.pictureUrl"
              :src="requestUrl+scope.row.pictureUrl"
              min-width="80"
              height="80"
              @click="lookBigImage(scope.row.pictureUrl)"
            >
          </template>
        </el-table-column>
        <el-table-column prop="assetCode" label="资产条码" width="120"></el-table-column>
        <el-table-column prop="assetName" label="资产名称" width="120"></el-table-column>
        <el-table-column prop="standardType" label="规格" width="120"></el-table-column>
        <el-table-column prop="sn" label="SN号" width="120"></el-table-column>
        <el-table-column prop="unit" label="计量单位" width="120"></el-table-column>
        <el-table-column prop="amount" label="金额(单位:万元)" width="200"></el-table-column>
        <!-- <el-table-column prop="useCompany" label="使用公司" width="120"></el-table-column> -->
        <el-table-column prop="ownOrganizationName" label="使用部门" width="120"></el-table-column>
        <el-table-column prop="buyDate" label="购入时间" width="120"></el-table-column>
        <el-table-column prop="useUser" label="使用人" width="120"></el-table-column>
        <el-table-column prop="ownOrganizationName" label="所属公司" width="200"></el-table-column>
        <el-table-column prop="area" label="区域" width="120"></el-table-column>
        <el-table-column prop="storageLocation" label="存放地点" width="120"></el-table-column>
        <el-table-column prop="deadLine" label="使用期限(月)" width="120"></el-table-column>
        <el-table-column prop="assetAdmin" label="管理员" width="120"></el-table-column>
        <el-table-column prop="remark" label="备注 " width="120"></el-table-column>
      </el-table>
      <br>
      <div class="block">
        <el-row :gutter="20">
          <el-col :span="4">
            <div class="grid-content bg-purple">
              <span class="demonstration">已选择{{this.assetList.length}}条</span>
            </div>
          </el-col>
          <el-col :span="10">
            <div class="grid-content bg-purple">
              <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage4"
                :page-sizes="[10, 20, 30, 40]"
                :page-size="10"
                layout="prev, pager, next, sizes, jumper"
                :total="this.total"
              ></el-pagination>
            </div>
          </el-col>
        </el-row>
      </div>
    </el-main>
  </div>
</template>
<script>
import { axiosPost, axiosGet ,requestUrl} from "@/api/index.js";
export default {
  data() {
    return {
      requestUrl:requestUrl,
      keywords: "",
      form: {
        useCompany: ""
      },
      total: 0,
      page: 1,
      pageSize: 10,
      tableData3: [],
      currentPage1: 5,
      currentPage2: 5,
      currentPage3: 5,
      currentPage4: 1,
      assetList: []
    };
  },

  //调用获取资产列表接口数据
  beforeMount() {
    this.getAssetList();
  },
  methods: {
    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionChange(val) {
      this.assetList = val;
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.page = val;
      this.getAssetList();
    },
    //将数据库对应的数字转换成在用 闲置 报废
    formatState: function(row, column) {
      return row.state === 1 ? "闲置" : row.state === 2 ? "在用" : "报废";
    },
    //获取资产列表数据接口用函数封装起来
    getAssetList: function() {
      var key1 = this.keywords;
      var bean = {
        page: this.page,
        pageSize: this.pageSize,
        key: key1,
        userId: localStorage.getItem("userId")
      };
      axiosGet("/Asset/GetAssetList", bean).then(res => {
        if (res.status == 200 && res.data.success) {
          this.tableData3 = res.data.data.list;
          this.total = res.data.data.total;
        }
      });
    },
    //搜索资产
    search() {
      // console.log(this.keywords);
      this.getAssetList();
    },
    //导出资产列表
    ExportAssetInfo: function() {
      var key1 = this.keywords;
      var bean = { key: key1 };
      /* axiosGet("/Asset/ExportAssetInfo", bean).then(res => {
        if (res.status == 200 && res.data.success) {
          // this.tableData3 = res.data.data;
        }
      }); */
       window.location.href = requestUrl + "Asset/ExportAssetInfo";
    }
  }
};
</script>
<style lang="scss" scoped>
.StatisticsList {
  height: 100%;
}
</style>
